/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javanetworking;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.io.Reader;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author NGUYEN
 */
public class FILES implements java.io.Serializable{

    private String tenfile;
    private List<String> tenchnk;

    public FILES(String tenfilei) {
        tenfile = tenfilei;
        tenchnk = new ArrayList<>();
    }

    public boolean kiemtrafile() {
        File fichunk;
        fichunk = new File("chunks/" + this.getTenfile());
        if (!fichunk.exists()) {
            return false;
        }
        return true;

    }

    public void loadchunk() throws FileNotFoundException, IOException 
    {
        String temp = "chunks/"+this.getTenfile()+"/"+this.getTenfile()+".chunk";
        String temp1 = "chunks/"+this.getTenfile()+"/";
        File ffile = new File(temp);
        if(!ffile.exists())
            return ;
       BufferedReader br = new BufferedReader(new FileReader(ffile));
       String str;
       while((str=br.readLine())!=null)
       {
           String[] fff = str.split(" ");
           String[] ff = fff[0].split("/");
           String temp2 = temp1 + ff[2];
           File FFF = new File(temp2);
           if(FFF.exists())
               this.tenchnk.add(ff[2]);
       }
     
    }
    
//    public static void main(String[] args) throws FileNotFoundException, IOException
//    {
//        String tenfile = "dopdf-7.exe";
//        FILES ff = new FILES(tenfile);
//        ff.loadchunk();
//        for(int i=0;i<ff.tenchnk.size();i++)
//            System.out.println(ff.tenchnk.get(i));
//               
//    }

    /**
     * @return the tenfile
     */
    public String getTenfile() {
        return tenfile;
    }

    /**
     * @param tenfile the tenfile to set
     */
    public void setTenfile(String tenfile) {
        this.tenfile = tenfile;
    }

    /**
     * @return the tenchnk
     */
    public List<String> getTenchnk() {
        return tenchnk;
    }

    /**
     * @param tenchnk the tenchnk to set
     */
    public void setTenchnk(List<String> tenchnk) {
        this.tenchnk = tenchnk;
    }
}
